package com.hfy.kandian.entity;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.Version;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;
import java.util.List;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * <p>
 * 
 * </p>
 *
 * @author HAN XIAOYANG
 * @since 2020-12-30
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="Bookshelf对象", description="")
public class Bookshelf implements Serializable {

    private static final long serialVersionUID=1L;

    @TableId(value = "bookshelf_id", type = IdType.AUTO)
    private Integer bookshelfId;

    @ApiModelProperty(value = "用户ID")
    private Integer userId;

    @ApiModelProperty(value = "用户收藏的书籍ID")
    private String bookIds;

    @TableField(fill = FieldFill.INSERT)
    private Date gmtCreate;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date gmtModified;


    public void addOneBookId(int bookId) {
        List<Integer> recList = JSONArray.parseArray(this.bookIds,Integer.class);
        recList.add(bookId);
        this.bookIds = JSON.toJSONString(recList);
    }
    public void deleteOneBookId(int bookId){
        List<Integer> recList = JSONArray.parseArray(this.bookIds,Integer.class);
        recList.remove(bookId);
        this.bookIds = JSON.toJSONString(recList);
    }

    public List<Integer> getBookIdList(){
        return JSONArray.parseArray(this.bookIds,Integer.class);
    }
}
